#include<stdio.h>
long k,h;
long getValue(long k){
    if(k==1)return 1;
    if(k%2==0) return h*getValue(k/2);
               return h*getValue((k-1)/2)+1; 
} 
int main(){
    scanf("%ld%ld",&k,&h);
    
    printf("%ld",getValue(k));
    return 0;
}
